home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / dec / qdss / qdregion.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-26  |  3.5 KB  |  116 lines

  1. /***********************************************************
  2. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. #include "regionstr.h"
  26.  
  27. #ifndef X11R4
  28. #define BOXBOUND( b1, b2)  \
  29.     (b1)->x1 = min( (b1)->x1, (b2)->x1);  \
  30.     (b1)->y1 = min( (b1)->y1, (b2)->y1);  \
  31.     (b1)->x2 = max( (b1)->x2, (b2)->x2);  \
  32.     (b1)->y2 = max( (b1)->y2, (b2)->y2);
  33. #endif
  34. /*
  35.  * Does what you really want; creates a region and initializes it
  36.  * to contain the argument boxes.
  37.  *
  38.  * Always creates at least one box, of zero size if necessary, although it is
  39.  * hidden from the caller, as numRects is set to zero
  40.  */
  41. RegionPtr
  42. qdRegionInit( boxes, nbox)
  43.     register BoxPtr    boxes;    /* length must agree with nbox */
  44.     register int    nbox;    /* */
  45. {
  46. #ifdef X11R4
  47. /* The code is simplified from miRectsToRegion in miregion.c */
  48.     extern RegionPtr miRegionCreate();
  49.     register RegionPtr    pRgn;
  50.     register BoxPtr    pBox;
  51.     register int        i;
  52.     Bool overlap; /* result ignored */
  53.  
  54.     pRgn = miRegionCreate(NullBox, 0);
  55.     if (!nbox)
  56.     return pRgn;
  57.     if (nbox == 1)
  58.     {
  59.     pRgn->extents = *boxes;
  60.     pRgn->data = (RegDataPtr)NULL;
  61.     return pRgn;
  62.     }
  63.     pRgn->data = (RegDataPtr)Xalloc(REGION_SZOF(nbox));
  64.     if (pRgn->data == NULL) {
  65.     return pRgn;
  66.     }
  67.     pRgn->data->size = nbox;
  68.     pRgn->data->numRects = nbox;
  69.     for (i = nbox, pBox = REGION_BOXPTR(pRgn); --i >= 0; boxes++)
  70.     {
  71.     *pBox = *boxes;
  72.     if ((pBox->x2 <= pBox->x1) || (pBox->y2 <= pBox->y1))
  73.         pRgn->data->numRects--;
  74.     else
  75.         pBox++;
  76.     }
  77.     pRgn->extents.x1 = pRgn->extents.x2 = 0;
  78.     miRegionValidate(pRgn, &overlap);
  79.     return pRgn;
  80. #else
  81.     register RegionPtr    temp;    /* new region */
  82.    
  83.     temp = (RegionPtr) Xalloc (sizeof (RegionRec));
  84.     temp->numRects = nbox;
  85.     temp->size = max(1, nbox);
  86.     temp->rects = (BoxPtr) Xalloc( temp->size * (sizeof(BoxRec)));
  87.     if ( nbox == 0)
  88.     {
  89.         temp->extents.x1 = temp->rects[0].x1 = 0;
  90.         temp->extents.y1 = temp->rects[0].y1 = 0;
  91.         temp->extents.x2 = temp->rects[0].x2 = 0;
  92.         temp->extents.y2 = temp->rects[0].y2 = 0;
  93.     }
  94.     else
  95.     {
  96.     int            ib;
  97.     register BoxPtr        temprects;
  98.  
  99.         temp->extents.x1 = MAXSHORT;
  100.         temp->extents.y1 = MAXSHORT;
  101.         temp->extents.x2 = MINSHORT;
  102.         temp->extents.y2 = MINSHORT;
  103.  
  104.     for (    ib=0, temprects=temp->rects;
  105.         ib<nbox;
  106.         ib++, boxes++, temprects++)
  107.     {
  108.         BOXBOUND( &temp->extents, boxes);
  109.         *temprects = *boxes;
  110.     }
  111.     }
  112.     miRegionValidate(temp);
  113.     return(temp);
  114. #endif
  115. }
  116.